<?php
use Buan\Config;
use Buan\UrlCommand;
use Buan\View;

$urlRoot = Config::get('ext.Scribble.urlRoot');
View::getGlobalView()->addJavascripts("{$urlRoot}/js/scribble/auth/user.list.js");

$loginAs = ScribbleAuth::authorize(ScribbleSession::getUser(), 'user-multi-login');
$currentUserId = ScribbleSession::getUser()->id;
?>

<div class="head">
	<h1>Users</h1>
</div>

<table class="list">
	<caption>Users</caption>
	<thead>
		<tr>
			<th>Display name</th>
			<th>Email</th>
			<th>Roles</th>
			<th>Last login</th>
			<th>Options</th>
		</tr>
	</thead>
	<tbody>
	<?php foreach($users as $u): ?>
		<tr>
			<td><?php $this->html->e($u->displayname); ?></td>
			<td><a href="<?php $this->html->eUrl(UrlCommand::createUrl('scribble', 'messaging', array('to'=>$u->email))); ?>"><?php $this->html->e($u->email); ?></a></td>
			<td></td>
			<td></td>
			<td>
				<a href="<?php $this->html->eUrl(UrlCommand::createUrl('scribble', 'auth', 'user', $u->id)); ?>">Edit</a>
				<?php if($loginAs && $currentUserId!=$u->id): ?>
					| <a href="<?php $this->html->eUrl(UrlCommand::createUrl('scribble', 'auth', 'user', $u->id, array('loginas'=>NULL))); ?>" title="Login temporarily as this user">Login as</a>
				<?php endif; ?>
			</td>
		</tr>
	<?php endforeach; ?>
	</tbody>
</table>